﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ProjectTest.Models
{
    public class QLDapAn
    {
        DBTestDataContext db = new DBTestDataContext();

        //lay toan bo dap an theo ma cau hoi
        public IEnumerable<DapAn> DapAnTheoCauHoi(int maCH)
        {
            return db.DapAns.Where(p => p.MaCH == maCH);
        }

        //Them thong tin dap an cho cau hoi 
        public void Create(DapAn Da)
        {
            try
            {
                db.DapAns.InsertOnSubmit(Da);
                db.SubmitChanges();
            }
            catch (Exception)
            {
                
                throw;
            }   
        }
        //sua thong tin dap an theo ma dap an
        public void Edit(DapAn DaEdited,int maDA)
        {
            DapAn da = db.DapAns.SingleOrDefault(p => p.MaDA == maDA);
            try
            {
                UpdeteInfo(da, DaEdited);
                db.SubmitChanges();
            }
            catch (Exception)
            {
                
                throw;
            }

        }

        public void UpdeteInfo(DapAn da, DapAn DaEdited)
        {
            da.MoTa = DaEdited.MoTa;
            da.MaCH = DaEdited.MaCH;
        }
        //xoa thong tin cua mot dap an theo ma dap an
        public void Delete(int maDA)
        {
            DapAn da = db.DapAns.SingleOrDefault(p => p.MaDA == maDA);
            try
            {
                db.DapAns.DeleteOnSubmit(da);
                db.SubmitChanges();
            }
            catch (Exception)
            {
                
                throw;
            }
        }
       
    }
}